home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 11
/
FM Towns Free Software Collection 11.iso
/
t_os
/
game
/
pr
/
src
/
prgrp.c
< prev
next >
Wrap
Text File
|
1995-08-20
|
10KB
|
479 lines
/*=====================================
"prgrp.c"
=====================================*/
#include <stdio.h>
#include <string.h>
#include <msdos.cf>
#include <egb.h>
//#include <concorde.h>
#include <malloc.h>
#include "prdef.h"
#define SKYCOL C32K(31, 5, 3)
#define GRDCOL C32K(10,10,12)
short *vram; //[VramX*240];
char *EgbWork; //[EgbWorkSize];
char *backBlc; //[320*240*2];
// PAGE p1,vp;
struct {
char *adr;
short sel;
short sx,sy,ex,ey;
} pbpara;
/*******
void filledBox( sx, sy, ex, ey, col ) // 画面外は暴走
int sx,sy,ex,ey;
short col;
{
short *vp=vram+sy*VramX+sx;
int x=ex-sx,y=ey-sy,i;
for(; y>=0; --y){
for(i=x; i>=0; --i)
*vp++=col ;
vp+=(VramX-x-1) ;
}
}
********/
void partClearScr( sy, ey, col )
int sy,ey;
short col;
#ifdef HISPEC
{
short *vp=vram+sy*VramX;
int i=(ey-sy+1)*VramX;
for(; i>0; --i)
*vp++ = col;
}
#else
{
memset( (char *)(vram+sy*VramX), 0, (ey-sy+1)*VramX*2);
}
#endif
initGrp()
{
int ret=1;
vram = (short *)malloc( sizeof(short)*VramX*240 );
EgbWork = malloc( EgbWorkSize );
if( vram==NULL || EgbWork==NULL )
return -1;
EGB_init( EgbWork, EgbWorkSize ); /* 初期化 */
EGB_resolution ( EgbWork, 0,10 ); /* 32k(320*240) */
EGB_resolution ( EgbWork, 1, 3 ); /* 16 (640*480) */
EGB_displayPage( EgbWork, 1, 3 ); /* 表示ページの指定 */
EGB_displayStart(EgbWork,3,0,0 ); /* 2*2 に拡大 */
EGB_displayStart(EgbWork,2,2,2 );
EGB_displayStart(EgbWork,1,0,0 );
EGB_displayStart(EgbWork,3,320,240);
EGB_writePage ( EgbWork, 1 );
EGB_writeMode ( EgbWork, 0 ); /*※描画モードの設定 */
EGB_paintMode ( EgbWork, 0x22 );
EGB_textSpace( EgbWork, 1 );
EGB_fontStyle( EgbWork, 1 );
EGB_textZoom( EgbWork, 0, 24, 48 ); /* ANK */
EGB_textZoom( EgbWork, 1, 32, 32 ); /* 漢字 */
/// YGH_initPage( &p1, SEG_VRAMP, 0x00000, 512,256 );
/// YGH_initPage( &vp, SEG_VIRTU, ADR(vram), 320,240 );
/// YGH_color( &vp, 0 );
/// YGH_filledBox( &vp, 0,0, 319,239 );
//filledBox( 0,0, 319,239, 0 );
partClearScr( 0, 239, 0 );
extern initFigImg();
initFigImg();
extern initBackBlc();
ret = initBackBlc();
if( ret<0 ) return ret;
pbpara.adr = (char *)vram ;
pbpara.sel = getds();
pbpara.sx = 0;
pbpara.sy = 0;
pbpara.ex = 319;
pbpara.ey = 239;
return 1;
}
void writeScreen()
{
EGB_writePage ( EgbWork, 0 );
EGB_putBlock( EgbWork, 0, (char *)&pbpara );
EGB_writePage ( EgbWork, 1 );
}
initBackBlc()
{
backBlc = malloc( 320*480*2 );
if( backBlc==NULL ){
puts("メモリが足りません(initBackBlc)");
return -1;
}
FILE *fp;
fp = fopen("back.blc","rb");
if (fp==NULL) {
puts("'back.blc'のオープンに失敗しました。");
return 0;
}
fread(backBlc,1,320*480*2,fp);
return 0;
}
void
clearVram( a, b, c )
int a,b,c ;
{
#if HeadY!=0
/// YGH_color( &vp, FRMCOL );
/// YGH_filledBox( &vp, 0, 0, VramX-1, HeadY-1 );
//filledBox( 0, 6, VramX-1, 9, FRMCOL );
partClearScr( 6, 9, FRMCOL );
#endif
int y = 240-SbjY-Mag*b/c ;
y = _max(0,y);
y = _min(480-VramY,y);
memcpy( (char *)(vram+320*HeadY), backBlc+320*y*2, 320*VramY*2 );
}
// 凸多角形専用 2Dポリゴン v2.0 95.7
#define py(a) pt[2*(a)+1]
#define px(a) pt[2*(a)]
void polygon( pol2d *pd )
{
int n=pd->n;
int *pt=((int *)pd)+1;
short col=pd->col;
int sy, ey, up;
int y;
int x0, n0, m0, dy0, dx0, ax0;
int x1, n1, m1, dy1, dx1, ax1;
short *vy;
up=0;
sy=py(0); ey=py(0);
for(y=1; y<n; ++y)
{
if( sy > py(y) ){
sy = py(y);
up = y;
}
ey = _max(ey,py(y));
}
ey = _min(ey,VramY-1);
x0 = x1 = px(up);
n0 = n1 = up;
m0 = (up+n-1)%n;
m1 = (up+1)%n;
dx0 = px(m0) - px(n0); dy0 = py(m0)-py(n0);
dx1 = px(m1) - px(n1); dy1 = py(m1)-py(n1);
ax0 = x0 * dy0; ax1 = x1 * dy1;
vy = ( sy>=0 ? vram+sy*VramX+HeadY*VramX : NULL );
for( y=sy; y<=ey; ++y )
{
// 左周りの x
if( py(m0)<=y ){
n0 = m0; m0 = (m0+n-1)%n;
dx0 = px(m0)-px(n0); dy0 = py(m0)-py(n0);
ax0 = px(n0) * dy0;
}
if( dy0==0 )
x0 = px(n0);
else{
x0 = ax0 / dy0;
ax0 += dx0;
}
// 右周りの x
if( py(m1)<=y ){
n1 = m1; m1 = (m1+1)%n;
dx1 = px(m1)-px(n1); dy1 = py(m1)-py(n1);
ax1 = px(n1) * dy1;
}
if( dy1==0 )
x1 = px(n1);
else{
x1 = ax1 / dy1;
ax1 += dx1;
}
// 描画
if( vy==NULL && y==0 ) vy = vram+VramX*HeadY;
if( vy!=NULL ){
up = _max(_min(x0,x1), 0);
sy = _min(_max(x0,x1),319); sy -= up;
register short *vp = vy; vp += up;
for(; 0<=sy; ++vp,--sy) *vp = col;
vy += VramX;
}
}
}
/*======================================
"prolpdsp.c" ( Overlap Display )
======================================*/
extern rdata *road; //[POLMAX]
extern int pflap;
extern short polmax,rd, blap[],flap[];
void textputs( char *s, int x, int y, int mode, int colc, int colb)
{
char para[256];
EGB_color( EgbWork, 0, colc );
EGB_color( EgbWork, 1, colb );
EGB_paintMode( EgbWork, 0x022 );
EGB_writeMode( EgbWork, mode );
WORD(para+0) = x; WORD(para+2) = y;
WORD(para+4) = strlen(s);
strcpy( para+6, s );
EGB_sjisString( EgbWork, para );
}
void putMess( char *str, int col )
{
EGB_textZoom( EgbWork, 0, 24, 48 ); // ANK
// EGB_writePage( EgbWork, 1 );
textputs( str, 320-13*25/2,250, 0, col, 0 );
// EGB_writePage( EgbWork, 0 );
}
void putLapTime( int lap, int time, int best )
{
int m, s, cs;
static char str[50];
if( lap>0 )
{
m = time/6000;
cs= time%100;
s =(time-m*6000)/100;
sprintf(str,"LAP%1d %2d:%02d.%02d",lap,m,s,cs);
EGB_textZoom( EgbWork, 0, 8, 16 ); // ANK
// EGB_writePage( EgbWork, 1 );
textputs(str,640-8*20,lap*20+47,0,(time<=best ? 10:13),0);
}
else
sprintf(str," START ");
putMess( str,14 );
}
void boxfil( int x1, int y1, int x2, int y2,/* int mode,*/ int col)
{
char para[8];
EGB_color( EgbWork, 2, col ); /* 2:FILL color */
EGB_paintMode( EgbWork, 0x20 );
// EGB_writeMode( EgbWork, mode );
WORD(para+0) = x1; WORD(para+2) = y1;
WORD(para+4) = x2; WORD(para+6) = y2;
EGB_rectangle( EgbWork, para );
EGB_paintMode( EgbWork, 0x22 );
}
void clearMess()
{
// EGB_writePage( EgbWork, 1 );
boxfil( 320-13*25/2,250-48, 320+15*25/2,250,0);
// EGB_writePage( EgbWork, 0 );
}
void clearScreen()
{
// EGB_writePage( EgbWork, 1 );
boxfil(0,0,639,479,0);
// EGB_writePage( EgbWork, 0 );
}
void putSpd( int spd )
{
int i,j;
short *vp,*vy=vram+VramX*6+20;
for(i=4; i>0; --i){
vp=vy;
for(j=0; j<spd; ++j,++vp)
*vp = C32K(0,_min(31,j/10),_max(31-j/10,0));
vy+=320;
}
}
void putlmap()
{
int i, j;
struct {
unsigned short num;
short p[8];
} pol;
pol.num = 4;
// EGB_writePage( EgbWork, 1 );
EGB_color( EgbWork, 2, 15 );
EGB_paintMode( EgbWork, 0x20 );
for(i=0; i<rd; ++i){
for(j=0; j<4; ++j){
pol.p[2*j ] = road[i].px[j] /80; // dot/20000
pol.p[2*j+1] = road[i].py[j] /80;
}
EGB_color( EgbWork, 2, 15 );
EGB_polygon( EgbWork, &pol );
}
EGB_paintMode( EgbWork, 0x22 );
// EGB_writePage( EgbWork, 0 );
}
void putLap( short *lap, char *str1, char *str2 )
{
int i,j, m,cs,s;
char lstr[50];
EGB_textZoom( EgbWork, 0, 16, 32 ); // ANK
// EGB_writePage( EgbWork, 1 );
textputs( str2, 320-17*13/2,34+33+34,0,12,0 );
textputs( str1, 320-17*13/2, 4+33+34,0,12,0 );
for(i=0,j=1; i<10; ++i)
{
if( i!=0 && lap[i-1]!=lap[i] ) j=i+1;
m=lap[i]/6000;
cs=lap[i]%100;
s=(lap[i]-m*6000)/100;
sprintf( lstr,"%2d.%2d:%02d.%02d",j,m,s,cs );
textputs( lstr, 320-17*11/2,(i+2)*34+33+34,0,
/*(lap[i]==pblap&&lap==blap)||*/
(lap[i]==pflap&&lap==flap) ? 15:13,0
);
}
// EGB_writePage( EgbWork, 0 );
}
/*====================
タイトル表示
====================*/
#define TITLEFILE "title.blc"
#define TITLEX 640
#define TITLEY 120
#define TITLESIZE (TITLEX*TITLEY/8)
static char title[TITLESIZE];
static int titleRead=0;
void readTitle()
{
FILE *fp;
int i;
fp = fopen(TITLEFILE,"rb");
if (fp==NULL) {
printf("File open error!! '%c'が見つかりません。\n",TITLEFILE);
return;
}
for (i=0; i<TITLESIZE; ++i)
title[i] = getc(fp);
fclose(fp);
}
void putTitle( short col )
{
if (!titleRead)
{
readTitle();
titleRead = 1;
}
struct {
char *bp ;
short sel ;
short sx,sy,ex,ey ;
} p ; /* EGB_putBlockのパラメータ */
p.bp = title ;
p.sel = getds() ;
// EGB_writePage( EgbWork, 1 );
// EGB_paintMode( EgbWork, 0x22 );
p.sx = 4 ;
p.ex = TITLEX-1 +4 ;
p.sy = 240-TITLEY/2+4 ;
p.ey = p.sy+TITLEY-1 ;
EGB_color( EgbWork, 0, 8 );
EGB_putBlockColor( EgbWork, 0, (char *)&p ) ;
p.sx = 0 ;
p.ex = TITLEX -1 ;
p.sy = 240-TITLEY/2 ;
p.ey = p.sy+TITLEY -1 ;
EGB_color( EgbWork, 0, col );
EGB_putBlockColor( EgbWork, 0, (char *)&p ) ;
// EGB_writePage( EgbWork, 0 );
}
/*=====================
Rest Time 表示
=====================*/
#define FIGFILE "fig0.blc"
#define FIGX 32
#define FIGY 48
#define FBUFSIZ (FIGX*FIGY/8)
static char fbuf[10][FBUFSIZ];
static int _CRestTime=-1;
static struct {
char *bp ;
short sel ;
short sx,sy,ex,ey ;
} fpara ;
initFigImg()
{
FILE *fp;
fp = fopen(FIGFILE,"rb");
if (fp==NULL) {
puts("'%c'のオープンに失敗しました。");
return 0;
}
int i,j;
for(j=0; j<=9; ++j)
for(i=0; i<FBUFSIZ; ++i)
fbuf[j][i] = getc(fp);
fclose(fp);
fpara.sel = getds() ;
fpara.sy = 48 ;
fpara.ey = 95 ;
}
void putRestTime( int rt )
{
if (rt==_CRestTime) return;
if (rt<0){
_CRestTime = -1;
return;
}
// EGB_writePage( EgbWork, 1 );
// EGB_paintMode( EgbWork, 0x22 );
EGB_writeMode( EgbWork, 9 );
EGB_color( EgbWork, 0, 14 );
if(rt/10!=_CRestTime/10 || _CRestTime<0){
fpara.sx = 320-FIGX ;
fpara.ex = 320-1 ;
fpara.bp = &fbuf[(rt/10)%10][0] ;
EGB_putBlockColor( EgbWork, 0, (char *)&fpara );
}
if(rt%10!=_CRestTime%10 || _CRestTime<0){
fpara.sx = 320 ;
fpara.ex = 320+FIGX-1 ;
fpara.bp = &fbuf[rt%10][0] ;
EGB_putBlockColor( EgbWork, 0, (char *)&fpara );
}
EGB_writeMode( EgbWork, 9 );
// EGB_writePage( EgbWork, 0 );
_CRestTime = rt;
}